<template>
  <div class="home">
    <div class="topHead clearfix">
      <span class="headLisL leftMenu" v-on:click="showMenu = !showMenu"><Icon type="navicon-round"></Icon></span>
      <span class="headLisL centerTitle">嗨学</span>
      <span @click="toSearch"><Icon v-show="showSearchIcon" class="searchIconHome" type="search"></Icon></span>
    </div>
    <router-view></router-view>
    <!-- 侧边栏菜单 -->
    <transition name="fade">
      <div class="menuShadeBox" v-if="showMenu" v-on:click="hideMenuBox($event)">
        <div class="sidebarMenuBox">
          <sidebarMenu v-on:listenChanges="monitorChild"></sidebarMenu>
        </div>
      </div>
    </transition>
    <!-- 底部说明 -->
    <footerBar v-show="showFooter"></footerBar>
  </div>
</template>

<script>
import sidebarMenu from './overallModules/sidebarMenu'
import footerBar from './overallModules/footerBar'
export default {
  name: 'home',
  components: {
    sidebarMenu,
    footerBar
  },
  data () {
    return {
      showMenu: false, // 是否显示侧边栏菜单
      showSearchIcon: false, // 是否显示搜索按钮图标
      showFooter: false // 是否显示底部信息
    }
  },
  watch: {
    $route (to) { // 监听路由的变化
      console.log(to.name)
      let hashName = to.name // 当前地址的路由名称
      if (hashName === 'index') { // 首页需要显示搜索按钮，其它页面不需要显示
        this.showSearchIcon = true
      } else {
        this.showSearchIcon = false
      }
      if (hashName === 'about') {
        this.showFooter = true
      } else {
        this.showFooter = false
      }
    }
  },
  mounted () {
    if (this.$route.name === 'index') {
      this.showSearchIcon = true
    }
  },
  methods: {
    hideMenuBox: function (ev) {
      console.log(ev.target.className)
      if (ev.target.className === 'menuShadeBox') {
        this.showMenu = false
      }
    },
    monitorChild: function (str) { // 从子组件接收一个参数
      this.showMenu = str
    },
    toSearch: function () { // 首页的搜索图标点击后进入搜索列表页
      this.$router.push({path: '/home/scenicList'})
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
@import "../../static/css/home.scss"
</style>
